package com.sunday.shoufen.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sunday.shoufen.R;
import com.sunday.shoufen.entity.BizShopSet;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘涛 on 2017/10/19.
 */

public class ShopSetListAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private List<BizShopSet> dataSet;
    private View.OnClickListener onClickListener;

    public ShopSetListAdapter(Context context) {
        this.mContext = context;
    }

    public ShopSetListAdapter(Context context, List<BizShopSet> dataSet) {
        this.mContext = context;
        this.dataSet = dataSet;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_shop_set_item, null);
        return new ListHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ListHolder viewHolder = (ListHolder) holder;
        BizShopSet item = dataSet.get(position);
        Glide.with(mContext).load(item.getImage())
                .error(R.mipmap.ic_default)
                .into(viewHolder.shopSetImg);
        viewHolder.shopSetName.setText(item.getProductName());
        viewHolder.priceNow.setText("￥" + item.getProductPrice());
        viewHolder.priceOld.setText("￥" + item.getMarketPrice());
        viewHolder.priceOld.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        viewHolder.saleNum.setText("已售" + item.getSaleCount());

        viewHolder.rlShopSet.setTag(item);
        viewHolder.rlShopSet.setOnClickListener(onClickListener);


    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return dataSet.size();
    }



    public void setDataSet(List<BizShopSet> dataSet) {
        this.dataSet = dataSet;
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }


    class ListHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.shop_set_img)
        ImageView shopSetImg;
        @Bind(R.id.shop_set_name)
        TextView shopSetName;
        @Bind(R.id.price_now)
        TextView priceNow;
        @Bind(R.id.price_old)
        TextView priceOld;
        @Bind(R.id.sale_num)
        TextView saleNum;
        @Bind(R.id.rl_shop_set)
        RelativeLayout rlShopSet;


        public ListHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
